<?php 
header("Content-type:text/html;charset=utf-8");
require_once('Admin/Model/NewsModel.php');
require_once('Admin/Controller/Controller.php');
class NewsController extends Controller{ 
  function __Construct(){
    parent::__Construct();
    $this->mod = 'news';
  }
  function listnews(){//获取列表
    $model=new NewsModel();
    $data= $model->getNewsList();
    $row= $model->getnewstype($id);
    //var_dump($row);
    //var_dump($data);
    $this->assign('news',$data);//assign方法目的往data里存数据
    $this->display();      
  }
  function newsform(){
    $this->display();
  }
function addnews(){//添加请求
   //获取表单数据
  $data= $_POST;
  //调用model方法添加用户的方法添加到数据库中
  $model=new NewsModel();
  $result = $model->addNews($data); 
  //如果成功跳转页面
  if($result){
    echo '添加成功 <a href="admin.php?c=news&m=listnews">如果没有跳转，请点这里跳转</a>';
    header("refresh:3;url='admin.php?c=news&m=listnews'");
  }
  else{
    echo "添加失败！<br/>";
    echo "<a href='admin.php?c=news&m=listnews'>返回</a>";
  }
}
function editnews(){
 $id=$_GET['id'];
 $model=new NewsModel();
 $result = $model->getNewsByID($id);
 //var_dump($result);
 $row= $model->getnewstype($id);
 if ($row['ntid']=='1'){
  $newstype = "政治新闻";
}else if($row['ntid']=='2'){
  $newstype = "社会新闻";
}else if($row['ntid']=='3'){
  $newstype = "财经新闻";
}else if($row['ntid']=='4'){
  $newstype = "军事新闻";
}else if($row['ntid']=='5'){
  $newstype = "体育新闻";
}else if($row['ntid']=='5'){
  $newstype = "娱乐新闻";
}  
// var_dump($row);
 $this->assign('news',$result);//assign方法目的往data里存数据
 $this->display(); 
}

function update(){
  $data = $_POST;
  $model = new NewsModel();
  $result = $model->update($data);
  if($result){
    echo '更新成功 <a href="admin.php?c=news&m=listnews">如果没有跳转，请点这里跳转</a>';
    //header("refresh:3;url='admin.php?c=news&m=listnews'");
  }
  else{
    echo "更新失败！<br/>";
    //echo "<a href='admin.php?c=news&m=listnews'>返回</a>";
  }
}
function del(){
  $id= $_GET['id'];
  $model=new NewsModel();
  $result = $model->delnews($id);
  if($result){
    echo '删除成功 <a href="admin.php?c=news&m=listnews">如果没有跳转，请点这里跳转</a>';
   // header("refresh:3;url='admin.php?c=news&m=listnews'");
  }
  else{
    echo "删除失败！<br/>";
    //echo "<a href='admin.php?c=news&m=listnews'>返回</a>";
  }


}
function search(){
  $one=$_POST;
   // var_dump($one);
  $model= new NewsModel();
  $data= $model->Search($one['key']);
  //var_dump($data);
  if($data){
    $this->assign('news',$data);
    $this->display();
  }
  else{
    echo "没有数据！<br/>";
    echo "<a href='admin.php?c=news&m=listnews'>返回</a>";
  }

}



}
?>
